package com.tianji.learning.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.learning.domain.dto.QuestionFormDTO;
import com.tianji.learning.domain.query.QuestionPageQuery;
import com.tianji.learning.domain.vo.QuestionVO;
import com.tianji.learning.service.IInteractionQuestionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 互动提问的问题表 前端控制器
 * </p>
 *
 * @author 东哥
 * @since 2024-06-25
 */
@RestController
@RequestMapping("/questions")
@Api(tags = "互动问答 - 用户端 - 问题相关接口")
@RequiredArgsConstructor
public class InteractionQuestionController {
    private final IInteractionQuestionService questionService;

    /**
     * 1、新增互动问题 (Day5- 课堂1)
     * @param questionDTO
     */
    @ApiOperation("新增互动问题")
    @PostMapping()
    public void saveQuestion(@Valid @RequestBody QuestionFormDTO questionDTO){
        questionService.saveQuestion(questionDTO);
    }

    /**
     * 2、分页查询互动问题 (Day5- 课堂2)
     * @param query
     */
    @ApiOperation("分页查询互动问题")
    @GetMapping("page")
    public PageDTO<QuestionVO> pageQuery(QuestionPageQuery query){
        return questionService.pageQuery(query);
    }

    /**
     * 3、根据ID查询互动问题 (Day5- 课堂3)
     * @param id 问题ID
     */
    @ApiOperation("根据ID查询互动问题")
    @GetMapping("{id}")
    public QuestionVO queryById(@PathVariable("id") Long id){
        return questionService.queryById(id);
    }
}
